/******************************************************************************
 * SVN­Version­Information:
 * ­­­­­­­­­­­­­­­­­­­­­­­­---------------------
 * $LastChangedRevision: 127 $
 * $LastChangedBy: SD $
 * $LastChangedDate: 2009-06-23 12:19:54 +0200 (Tue, 23 Jun 2009) $
 * $HeadURL: svn://lvis10.fbm.fht-stuttgart.de/common/Common/src/de/hft_stuttgart/botwar/common/models/RobotInfo.java $
 ******************************************************************************/
package de.hft_stuttgart.botwar.common.models;

import java.io.Serializable;

/**
 * Class to hold all information about a robot.
 * @author sdegiorgi@gmail.com, pmv-mail@gmx.de
 */
public class RobotInfo implements Serializable {

    private final int robotID;
    private final String ownerID;
    private final String robotName;
    private final ArmamentInfo armament;
    private final ChassisInfo chassis;
    private final ShieldInfo shield;

    /**
     * New robot info.
     * @param ownerID of a robot
     * @param robotName of a robot
     * @param armament of a robot
     * @param chassis of a robot
     * @param shield of a robot
     */
    public RobotInfo(final String ownerID, final String robotName,
            final ArmamentInfo armament, final ChassisInfo chassis,
            final ShieldInfo shield) {

        this.robotID = ownerID.hashCode() * robotName.hashCode();
        this.ownerID = ownerID;
        this.robotName = robotName;
        this.armament = armament;
        this.chassis = chassis;
        this.shield = shield;
    }

    /**
     * New robot info.
     * @param robotID of a robot
     * @param ownerID of a robot
     * @param robotName of a robot
     * @param armament of a robot
     * @param chassis of a robot
     * @param shield of a robot
     */
    public RobotInfo(final int robotID, final String ownerID,
            final String robotName, final ArmamentInfo armament,
            final ChassisInfo chassis, final ShieldInfo shield) {

        this.robotID = robotID;
        this.ownerID = ownerID;
        this.robotName = robotName;
        this.armament = armament;
        this.chassis = chassis;
        this.shield = shield;
    }

    /**
     * Returns the energy.
     * @return shield.getHealth() health of a shiel
     */
    public int getEnergy() {
        return shield.getHealth();
    }

    /**
     * Returns the fire power of a armament.
     * @return armament.getFirePower() fire power of armament
     */
    public int getFirePower() {
        return armament.getFirePower();
    }

    /**
     * Returns the name of the robot.
     * @return robotName name of robot
     */
    public String getRobotName() {
        return robotName;
    }

    /**
     * Returns the distance of a weapon.
     * @return armament.getDistance() distance of weapon
     */
    public double getWeaponRange() {
        return armament.getDistance();
    }

    /**
     * Returns robot id.
     * @return robotID id of robot
     */
    public int getRobotID() {
        return robotID;
    }

    /**
     * Returns the owner id of a robot.
     * @return ownerID of robot
     */
    public String getOwnerID() {
        return ownerID;
    }

    /**
     * Returns the armament info
     * @return armament info
     */
    public ArmamentInfo getArmament() {
        return armament;
    }

    /**
     * Returns the chassis info.
     * @return chassis info
     */
    public ChassisInfo getChassis() {
        return chassis;
    }

    /**
     * Return the shield info.
     * @return shield info
     */
    public ShieldInfo getShield() {
        return shield;
    }

    /**
     * Returns the complete price of a robot.
     * @return (armament.getCost() + chassis.getCost() + shield.getCost())
     * of robot
     */
    public int getCompleteCost() {
        return (armament.getCost() + chassis.getCost() + shield.getCost());
    }

    /**
     * Return the level rank.
     * @return levelRank needed level for this robot
     */
    public int getLevelRank() {
        int levelRank = armament.getLevelRank();
        if (levelRank < chassis.getLevelRank()) {
            levelRank = chassis.getLevelRank();
        }
        if (levelRank < shield.getLevelRank()) {
            levelRank = shield.getLevelRank();
        }
        return levelRank;
    }

    /**
     * Overrides method equals()
     * @param obj to compare
     * @return boolean true or false
     */
    @Override
    public boolean equals(final Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        RobotInfo rInfo = (RobotInfo) obj;
        if (this.getRobotID() == (rInfo.getRobotID())) {
            return true;
        }
        return false;
    }

    /**
     * Overrides method hashCode
     * @return hash code
     */
    @Override
    public int hashCode() {
        int hash = 5;
        hash = 97 * hash + this.robotID;
        return hash;
    }

    /**
     * Overrides method toString.
     * @return Text representation of this instance.
     */
    @Override
    public String toString() {
        return String.format("RobotID: %d, Name: %s, Owner: %s, " +
                "Firepower: %d, " + "Energy: %d, Range: %f",
                this.getRobotID(), this.getRobotName(), this.getOwnerID(),
                this.getFirePower(), this.getEnergy(), this.getWeaponRange());
    }
}

